//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ConfigurationWizard.Properties;

namespace ConfigurationWizard.Controls
{
    public partial class DependencyViewControl : UserControl
    {
        private string action;

        public DependencyViewControl(string title, string explanation, string downloadUrl, string scriptName)
        {
            InitializeComponent();
            SetDependencyInformation(title, explanation, downloadUrl, scriptName);
            ShowMinimumDependecyInformation(Resources.unknown);
           
        }

        private void SetDependencyInformation(string title, string explanation, string downloadUrl, string scriptName)
        {
            this.titleLabel.Text = title;
            this.descriptionLabel.Text = explanation;

            if (string.IsNullOrEmpty(downloadUrl))
            {
                this.downloadLink.Text = "Install";
                this.action = scriptName;
            }
            else 
            {
                this.downloadLink.Text = "Download";
                this.action = downloadUrl;
            }
        }

        private void ShowMinimumDependecyInformation(Bitmap image)
        {
            this.Height = 26;
            this.statusPictureBox.Image = image;
            this.descriptionLabel.Visible = false;
            this.downloadLink.Visible = false;
            this.titleLabel.ForeColor = Color.FromArgb(117, 117, 117);
        }

        private void ShowFullDependecyInformation(Bitmap image)
        {
            this.Height = 72;
            this.statusPictureBox.Image = image;
            this.descriptionLabel.Visible = true;
            this.downloadLink.Visible = true;
        }

        public void SetSuccessMode()
        {
            ShowMinimumDependecyInformation(Resources.good);
        }

        public void SetWarningMode()
        {
            ShowFullDependecyInformation(Resources.warning);
        }

        public void SetErrorMode()
        {
            ShowFullDependecyInformation(Resources.bad);
        }

        private void downloadLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo = new System.Diagnostics.ProcessStartInfo(this.action);
            process.StartInfo.UseShellExecute = true;
            process.Start();
        }
    }
}
